var ProjectList = {};
ProjectList.contextpath = "";
ProjectList.initPage = function(contextpath) {
	ProjectList.contextpath = contextpath;
	ProjectList.project_delete_permission =$("#project-delete").val();

	// 查看项目详情
	$(document).on("click", ".seeDetail", function() {
		ProjectList.openSelect($(this).attr("data"));
	});
	
	// 查看项目文档
	$(document).on("click", ".getDocument", function() {
		ProjectList.getDoucument($(this).attr("data"));
	});
	
	layui.use('table', function() {
		var table = layui.table;
		// 第一个实例
		table.render({
			elem : '#demo',
			toolbar : '#toolbarDemo'
			// ,height: 500
			// ,width :900
			,
			url : '/web2019/project/projectList.action' // 数据接口
			,
			page : true // 开启分页
			,
			response : {
				statusName : 'code' // 规定数据状态的字段名称，默认：code
				,
				statusCode : "0000" // 规定成功的状态码，默认：0
				,
				msgName : 'message' // 规定状态信息的字段名称，默认：msg
				,
				countName : 'total' // 规定数据总数的字段名称，默认：count
			},
			cols : [ [ // 表头
			{
				field : 'projectId',
				title : 'ID',
				width : 180,
				sort : true,
				fixed : 'left'
			}, {
				field : 'projectName',
				title : '项目名',
				width : 180
			}, {
				field : 'description',
				title : '描述',
				width : 360,
				sort : true
			}, {
				title : '操作',
				templet : ProjectList.setOperate,
				width : 360,
				align : 'center',
				fixed : 'right'
			} ] ]
		});

	});
}
ProjectList.setOperate=function(data){
	var projectId = data.projectId
	var btnHtml = "";
	btnHtml += '<button type="button" class="layui-btn layui-btn-xs seeDetail" data="'
			+ projectId + '">查看</button>';
	btnHtml += '<button type="button" class="layui-btn layui-btn-xs" onclick="ProjectList.doExport('
		+ projectId + ')">导出</button>';
	btnHtml += '<button type="button" class="layui-btn layui-btn-xs getDocument" data="'
		+ projectId + '">生成在线文档</button>';
		
	if(ProjectList.project_delete_permission=="1"){
		btnHtml += '<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" onclick="ProjectList.doDelete('
			+ projectId + ')">删除</button>';	
	}
	return btnHtml;
}
ProjectList.openSelect=function(projectId){
	window.location.href="/"+ProjectList.contextpath+"/project/projectDetail.action?projectId="+projectId;
}
/**
 * 生成在线文档
 */
ProjectList.getDoucument=function(projectId){
	var data ={"projectId":projectId};
	Common.callClient("/web2019/project/getProjectDoucument.action",data,function(data){
		if (data.code == "0000") {
			layer.alert(data.message);
		} else {
			layer.alert(data.message);
		}
	});
}
ProjectList.doDelete=function(projectId){
	
}
ProjectList.doExport=function(projectId){
	$("#projectId").val(projectId);
	$("#exportForm").submit();
}